import 'package:flutter/material.dart';
import 'package:flutter_demo/generated/l10n.dart';
import 'package:flutter_demo/ui/ContainerTest.dart';
import 'package:flutter_demo/ui/GetStateObjectRoute.dart';
import 'package:flutter_demo/ui/graphQL_test/hql_paging.dart';
import 'package:flutter_demo/ui/route/RouterParameterRoute.dart';
import 'package:flutter_demo/ui/route/gorouter/path_and_query_parameters.dart';
import 'package:flutter_demo/ui/route/gorouter/shell_route.dart';
import 'package:flutter_demo/ui/RowTest.dart';
import 'package:flutter_demo/ui/gird/grid_list_demo.dart';
import 'package:flutter_demo/ui/sp.dart';
import 'package:flutter_demo/ui/state/list.dart';
import 'package:flutter_demo/ui/tab/list.dart';
import 'package:flutter_demo/ui/widget/WidgetDemo.dart';
import 'package:flutter_demo/utils/context/one_context_utils.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'ui/apply/CupertinoAppTest.dart';
import 'ui/apply/counter.dart';
import 'ui/gird/grid_icon_count_demo.dart';
import 'ui/list/list_view_ListTile_image_text.dart';
import 'ui/ColumnTest.dart';
import 'ui/ExpandedTest.dart';
import 'ui/apply/SettingsPage.dart';
import 'ui/apply/StrawberryPavlovaRecipeApp.dart';
import 'ui/gird/grid_extent_demo.dart';
import 'ui/list/list_view_ListTile_text.dart';
import 'ui/list/list_view_builder.dart';
import 'ui/list/list_view_horizontal.dart';
import 'ui/list/list_view_list_tile.dart';
import 'ui/list/list_view_separated.dart';

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: 'Welcome to Flutter',
        // home: FirstPage(),
        initialRoute: "/", //名为"/"的路由作为应用的home(首页)
        //本地化值集合的代理类列表
        localizationsDelegates: const [
          S.delegate,
          GlobalMaterialLocalizations.delegate,
          GlobalCupertinoLocalizations.delegate,
          GlobalWidgetsLocalizations.delegate,
        ],
        supportedLocales: S.delegate.supportedLocales,
        builder: OneContextUtils.oneContextBuilder,
        navigatorKey: OneContextUtils.oneContextKey,
        routes: {
          "/": (context) => FirstPage(), //注册首页路由
          'Widget': (context) => const WidgetDemo(),
          'ListViewBuilder': (context) => ListViewBuilder(),
          'CounterWidgetApp': (context) => const CounterWidgetApp(),
          'CupertinoAppTest': (context) => const CupertinoAppTest(),
          'RowTest': (context) => const RowTest(),
          'ColumnTest': (context) => const ColumnTest(),
          'ImageExpandedTest': (context) => const ImageExpandedTest(),
          'StrawberryPavlovaRecipeApp': (context) =>
              const StrawberryPavlovaRecipeApp(),
          'ContainerApp': (context) => const ContainerApp(),
          'GridListDemo': (context) => const GridListDemo(),
          'GridIconCountDemo': (context) => const GridIconCountDemo(),
          'GridExtentDemo': (context) => const GridExtentDemo(),
          'ListViewTest': (context) => ListViewTest(),
          'ListViewImageText': (context) => ListViewImageText(),
          'ListViewListTile': (context) => ListViewListTile(),
          'SettingsPage': (context) => SettingsPage(),
          'ListViewHorizontal': (context) => const ListViewHorizontal(),
          'ListViewSeparated': (context) => ListViewSeparated(),
          'GetStateObjectRoute': (context) => const GetStateObjectRoute(),
          'StateDemoList': (context) => const StateDemoList(),
          'RouterParameterRoute': (context) => const RouterParameterRoute(),
          'ShellRouteExampleApp': (context) => ShellRouteExampleApp(),
          'PathAndQueryParameters': (context) => PathAndQueryParameters(),
          'TabDemoList': (context) => const TabDemoList(),
          'FetchMoreWidgetScreen': (context) => const FetchMoreWidgetScreen(),
        });
  }
}

class FirstPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Welcome to Flutter'),
      ),
      body: ListView.builder(
        itemCount: listData.length,
        itemBuilder: (BuildContext context, int index) {
          return ListTile(
            title: Text(listData[index].title),
            onTap: () {
              Navigator.pushNamed(context, listData[index].path);
              for (var value in listData) {
                print(value);
              }
            },
          );
        },
        // children: [
        //   ListTile(
        //     title: const Text('ListViewImageText'),
        //     onTap: () {
        //       Navigator.pushNamed(context, 'SettingsPage');
        //     },
        //   ),
        //   MaterialButton(
        //       onPressed: () {
        //         Navigator.push(context, MaterialPageRoute(builder: (context) {
        //           return const GridIconCountDemo();
        //         }));
        //       },
        //       child: const Text('GridIconCountDemo'))
        // ],
      ),
    );
  }
}

class Item {
  String title;
  String path;

  Item(this.title, this.path);
}

List<Item> listData = [
  Item("Widget", "Widget"),
  Item("CupertinoAppTest", "CupertinoAppTest"),
  Item("RowTest", "RowTest"),
  Item("ColumnTest", "ColumnTest"),
  Item("ImageExpandedTest", "ImageExpandedTest"),
  Item("StrawberryPavlovaRecipeApp", "StrawberryPavlovaRecipeApp"),
  Item("ContainerApp", "ContainerApp"),
  Item("GridListDemo", "GridListDemo"),
  Item("GridIconCountDemo", "GridIconCountDemo"),
  Item("GridExtentDemo", "GridExtentDemo"),
  Item("ListViewTest", "ListViewTest"),
  Item("ListViewImageText", "ListViewImageText"),
  Item("ListViewBuilder", "ListViewBuilder"),
  Item("ListViewListTile", "ListViewListTile"),
  Item("SettingsPage", "SettingsPage"),
  Item("ListViewHorizontal", "ListViewHorizontal"),
  Item("ListViewSeparated", "ListViewSeparated"),
  Item("CounterWidgetApp(生命周期)", "CounterWidgetApp"),
  Item("抽屉(子树中获取State对象,SnackBar、GlobalKey)", "GetStateObjectRoute"),
  Item("状态管理", "StateDemoList"),
  Item("路由(传递[非命名路由的传值方式]、接受参数)", "RouterParameterRoute"),
  Item("GoRouter(ShellRoute,BottomNavigationBar)", "ShellRouteExampleApp"),
  Item("Path And Query Parameters", "PathAndQueryParameters"),
  Item("Tab", "TabDemoList"),
  Item("sp", "SharedPreferencesExample"),
  Item("FetchMoreWidgetScreen", "FetchMoreWidgetScreen"),
];
